package lxx.zhihudailypaper.adapter;

import java.util.List;



import lxx.zhihudailypaper.R;
import lxx.zhihudailypaper.bean.StoriesBean;
import lxx.zhihudailypaper.view.MyImageView;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class StoriesAdapter extends BaseAdapter{
	
	private List<StoriesBean> list_stories;
	private Context ctx;
	
	public StoriesAdapter (Context ctx, List<StoriesBean> list_stories){
		this.ctx = ctx;
		this.list_stories = list_stories;
	}
	
	@Override
	public int getCount() {
		return list_stories.size();
	}

	@Override
	public Object getItem(int position) {
		return list_stories.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder = null;
		
		if(convertView == null){			
			convertView = View.inflate(ctx, R.layout.item_stories_layout, null);
			holder = new ViewHolder();
			holder.images = (MyImageView) convertView.findViewById(R.id.miv_photo);
			holder.title = (TextView) convertView.findViewById(R.id.tv_title);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		
		StoriesBean bean = (StoriesBean) getItem(position);
		holder.images.setImageUrl(bean.getImages());
		holder.title.setText(bean.getTitle());

		return convertView;
	}
	
	static class ViewHolder{
		TextView title;
		MyImageView images;
	}
}

